package com.yyt.springbootdemorabbitmq.sender;

import com.yyt.springbootdemorabbitmq.pojo.User;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author: yeyangtao
 * @date: 2019/12/3 15:10
 */
@Component
public class HelloSender {
    @Resource
    private AmqpTemplate amqpTemplate;

    public void send() {
        String content = "hello at " + new Date();
        System.out.println("发送消息：" + content);
        this.amqpTemplate.convertAndSend("string", content);
    }

    public void sendObj() {
        User user = new User("yyt", "123");
        System.out.println("发送对象：" + user);
        this.amqpTemplate.convertAndSend("object", user);
    }
}
